/******************************************************************************
 *                  Shanghai ChipON Micro-Electronic Co.,Ltd
 ******************************************************************************
 *  @File Name        : kf8a100fxx_osc.h
 *  @Author           : ChipON AE/FAE Group
 *  @Date             : 2023-12-19
 *  @HW Version       : KF8A100Fxx
 *  @Lib Version      : V2.0.1
 *  @Description      : This file provides the driver for the osc module
 ******************************************************************************
 *  Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd
 *  All rights reserved.
 *
 *  This software is copyright protected and proprietary to
 *  Shanghai ChipON Micro-Electronic Co.,Ltd.
 *****************************************************************************/
/******************************************************************************
 *  |Date        |Version  |Author       |Description
 ******************************************************************************
 *  |2023-12-23  |V2.0     |Wang Junxiong|New creat
 *****************************************************************************/

#ifndef KF8A100FXX_OSC_H
#define KF8A100FXX_OSC_H

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
 *                      Include Files
 *****************************************************************************/
#include "kf8a100fxx.h"
/******************************************************************************
 *                      Macro or Inline
 *****************************************************************************/

/**
 * @brief Osc Update div
 * x: Osc_IrcsType.
 * OSC_DIV_256
 * OSC_DIV_64
 * OSC_DIV_32
 * OSC_DIV_16
 * OSC_DIV_8
 * OSC_DIV_4
 * OSC_DIV_2
 * OSC_DIV_1
 */
#define OSC_UPDATE_DIV(x) (OSCCTL = ((uint8_t)OSCCTL & 0x8fu) | x)
/******************************************************************************
 *                      Typedef Definitions
 *****************************************************************************/

/**
 * @brief OSC frequency coefficient.
 */
typedef enum
{
    OSC_DIV_256 = 0u,
    OSC_DIV_64  = 16u,
    OSC_DIV_32  = 32u,
    OSC_DIV_16  = 48u,
    OSC_DIV_8   = 64u,
    OSC_DIV_4   = 80u,
    OSC_DIV_2   = 96u,
    OSC_DIV_1   = 112u
} Osc_IrcsType;

/**
 * @brief OSC system clock source selection.
 */
typedef enum
{
    /** @brief Internal high frequency crystal: 16MHz  */
    OSC_INTHF = 0u,
    /** @brief Internal low frequency crystal: 32KHz  */
    OSC_INTLF = 4u,
    /** @brief External high frequency crystal  */
    OSC_EXTHF = 12u
} OSC_SourceType;
/******************************************************************************
 *                      Export Variables
 *****************************************************************************/

/******************************************************************************
 *                      Export Functions
 *****************************************************************************/

/**
 * @brief Initialize the OSC, system clock must not fall below 4MHz.
 *
 * @param Source OSC system clock source selection.
 * @param Division OSC frequency coefficient.
 */
void Osc_Init(OSC_SourceType Source, Osc_IrcsType Division);

/**
 * @brief OSC Update Clock Source, system clock must not fall below 4MHz.
 *
 * @param Source OSC system clock source selection.
 */
void OSC_UpdateSource(OSC_SourceType Source);

#ifdef __cplusplus
}
#endif

#endif
/* EOF */
